application: Use the new API to get the startup notification ID
authorMario Sanchez Prada <msanchez@gnome.org>
Mon, 4 Jun 2018 16:27:45 +0000 (17:27 +0100)
committerMario Sanchez Prada <msanchez@gnome.org>
Mon, 11 Jun 2018 15:28:24 +0000 (16:28 +0100)
The DESKTOP_STARTUP_ID gets cleared early after the process is spawned,
meaning that it's too late at add_platform_data() to pick it up and send
it over to the primary instance, as it will be always unset at that point.

To solve this, we use the new gdk_display_get_startup_notification_id()
method to pull the startup notification ID for the application, if present,
out of the display and pass it over to that primary instance.

https://gitlab.gnome.org/GNOME/gtk/issues/1084

gtk/gtkapplication.c

index 91b14af558172ea0e627c8a12becd7f389047f5e..dd2aeb038cbe4453b07347ab0624cccd506dc518 100644 (file)
@@ -329,7 +329,7 @@ static void
 gtk_application_add_platform_data (GApplication    *application,
                                    GVariantBuilder *builder)
 {
-  const gchar *startup_id;
+  GdkDisplay *display;
 
   /* This is slightly evil.
    *
@@ -338,11 +338,16 @@ gtk_application_add_platform_data (GApplication    *application,
    *
    * So we do all the things... which currently is just one thing.
    */
-  startup_id = getenv ("DESKTOP_STARTUP_ID");
+  display = gdk_display_get_default ();
+  if (display)
+    {
+      const gchar *startup_id;
 
-  if (startup_id && g_utf8_validate (startup_id, -1, NULL))
-    g_variant_builder_add (builder, "{sv}", "desktop-startup-id",
-                           g_variant_new_string (startup_id));
+      startup_id = gdk_display_get_startup_notification_id (display);
+      if (startup_id && g_utf8_validate (startup_id, -1, NULL))
+        g_variant_builder_add (builder, "{sv}", "desktop-startup-id",
+                               g_variant_new_string (startup_id));
+    }
 }
 
 static void